﻿@model SportClubMvc.Model.SportsClubClasses.NewsModel
<div class="row">
    @Html.HiddenFor(x => x.Id, new { id = "newsId" })
    <div class="span8">
        <div class="control-group">
            <div class="controls">
                <h3>@Model.Header</h3>
            </div>
        </div>

        <div class="control-group">
            <div class="controls">
                <p>&nbsp;</p>
                <p>
                    @Html.Raw(HttpUtility.HtmlDecode(Model.Text))
                </p>
            </div>
        </div>
        <p>&nbsp;</p>
        <div class="control-group">
            <div class="controls">
                Forfatter: @Model.Creator
            </div>
        </div>

        <div class="control-group">
            <div class="controls">
                Dato: @Model.DateCreated
            </div>
        </div>

        @if (User.Identity.IsAuthenticated && User.Identity.Name.Equals(Model.Creator))
        {
            <div class="button">
                    <a href="@Url.Action("Edit", new { Id = Model.Id })">Endre</a>
                    &nbsp;
                    <a style="background-color: rgb(215, 84, 84);" href="#" onclick="ShowDeleteNewsModal()">Slett</a>
            </div>
               
        }
        <p>
            &nbsp;
        </p>
    </div>
    <div class="span3 pull-right">
        <h4>Andre nyheter</h4>
        <ul id="otherNews">
        </ul>
    </div>
</div>

<div class="modal hide fade" id="deleteNewsModal">
    <div class="modal-header">
        <h3>Slette nyhet?</h3>
    </div>
    <div class="modal-footer">
        <div class="button">
            <a style="background-color: rgb(215, 84, 84);" href="@Url.Action("Delete", new {Model.Id })">Slett</a>
            &nbsp;
            <a href="#" data-dismiss="modal">Avbryt</a>
        </div>
    </div>
</div>

@section scripts{
    <script type="text/javascript">
        $(function () {
            var url = "/News/GetRelatedNews";
            var id = $('#newsId').val();

            $.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                url: url,
                data: { id: id },
                dataType: "json",
                success: function (data) { //do some stuff...and show results
                    for (var i = 0; i < data.News.length; i++) {
                        $('#otherNews').append('<li><a href="' + data.News[i].Id + '">' + data.News[i].Header + '</a></li>');
                    }
                }
            });
        });

        function ShowDeleteNewsModal() {
            $('#deleteNewsModal').modal('show');
        }
    </script>
}